from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User


## AREAS AND SUBAREAS

class Area(models.Model):
    area = models.CharField(max_length=50,blank=False,null=False)

    def __unicode__(self):
        return '%s' % (self.area)

    class Meta:
        verbose_name = _('Area')
        verbose_name_plural = _('Areas')
        ordering = ['area']

class SubArea(models.Model):
    sub_area = models.CharField(max_length=50,blank=True,null=True)
    area = models.ForeignKey(Area,blank=False,null=False)

    def __unicode__(self):
        return '%s' % (self.sub_area)

    class Meta:
        verbose_name = _('SubArea')
        verbose_name_plural = _('SubAreas')
        ordering = ['sub_area']


## DISSERTATIONS (TRABAJOS)

class Status(models.Model):
    status = models.CharField(max_length=50,blank=False,null=False)

    def __unicode__(self):
        return '%s' % (self.status)
    
    class Meta:
        verbose_name = _('Status')
        verbose_name_plural = _('Status')
        ordering = ['status']

class Dissertation(models.Model):
    date = models.DateField(blank=True,null=True)
    author_first_name = models.CharField(max_length=50,blank=True,null=True)
    author_last_name = models.CharField(max_length=50,blank=True,null=True)
    author_email = models.CharField(max_length=50,blank=True,null=True)
    author_phone = models.CharField(max_length=15,blank=True,null=True)
    filiation = models.CharField(max_length=50,blank=True,null=True)
    filiation_country = models.CharField(max_length=50,blank=True,null=True)
    presenter = models.CharField(max_length=50,blank=True,null=True)
    main_author = models.CharField(max_length=50,blank=True,null=True)
    registered = models.NullBooleanField(blank=True,null=True)
    area = models.ForeignKey(Area,blank=True,null=True)
    sub_area = models.ForeignKey(SubArea,blank=True,null=True)
    language = models.CharField(max_length=50,blank=True,null=True)
    title = models.CharField(max_length=50,blank=True,null=True)
    dissertation = models.TextField(blank=True, null=True)
    dissertation_type = models.CharField(max_length=50,blank=True,null=True)
    status = models.ForeignKey(Status,blank=True,null=True)

    def __unicode__(self):
        return '%s' % (self.title)
    
    class Meta:
        verbose_name = _('Dissertation')
        verbose_name_plural = _('Dissertations')
        ordering = ['-date']


## CONTACTS / USERS

class Contact(models.Model):
    contact = models.ForeignKey(User)
    area = models.ForeignKey(Area,blank=False,null=False)
    sub_area = models.ForeignKey(SubArea,blank=False,null=False)

    def __unicode__(self):
        return '%s' % (self.contact)
    
    class Meta:
        verbose_name = _('Contact')
        verbose_name_plural = _('Contacts')
        ordering = ['contact']


## COMMENTS

class Comment(models.Model):
    date_time = models.DateTimeField(blank=True,null=True)
    author = models.ForeignKey(Contact,null=True)
    comment = models.TextField(null=True)
    dissertation = models.ForeignKey(Dissertation,blank=True,null=True)
    
    def __unicode__(self):
        return '%s %s: %s' % (self.date_time, self.author, self.comment)
    
    class Meta:
        verbose_name = _('Comment')
        verbose_name_plural = _('Comments')
        ordering = ['-date_time']
